package com.yipin.neimeng.controller;


import com.alibaba.druid.util.StringUtils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.yipin.neimeng.request.YunShuOrderRequest;
import com.yipin.neimeng.request.YunShuSendMessageCodeRequest;
import com.yipin.neimeng.service.NeiMengCmccMsgService;
import com.yipin.neimeng.service.NeimengCmccOrdersService;

import com.yipin.neimeng.vo.ResultMsg;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
import java.security.MessageDigest;
import java.text.SimpleDateFormat;
import java.util.*;



@Slf4j
@RestController
@RequestMapping(value = "/neimeng/cmcc")
public class NeiMengCmccController {

    private static final String METHOD_URL = "CRM_CS_SRVUPD_SMS_SEND_002";   //接口编码

    private static final String AppId = "501146";   //应用AppId

    private static final String Url = "http://218.202.142.37:11001/oppf";
    private static final String OWNKEY = "1587522";
    private static final String APP_KEY = "6b968fcf48a19c399090e99a52747c61"; //私钥
    @Autowired
     NeiMengCmccMsgService neiMengCmccMsgService;

    @Autowired
    NeimengCmccOrdersService neimengCmccOrdersService;

    @PostMapping("/sendMsg")
    public ResultMsg<?> sendMsg(@RequestBody YunShuSendMessageCodeRequest yunShuSendMessageCodeRequest){
        log.info("云梳下发验证码请求参数："+yunShuSendMessageCodeRequest);
        return neiMengCmccMsgService.sendMsg(yunShuSendMessageCodeRequest);
    }

    @PostMapping("/sendorder")
    public ResultMsg<?> sendOrder(@RequestBody YunShuOrderRequest yunShuOrderRequest){
        log.info("云梳下发校验验证码参数："+yunShuOrderRequest);
        return neimengCmccOrdersService.sendorder(yunShuOrderRequest);
    }

    @PostMapping("/selectOrder")
    public ResultMsg<?> selectOrder(@RequestBody YunShuOrderRequest yunShuOrderRequest){
        log.info("云梳查询订单参数："+yunShuOrderRequest);
        return neimengCmccOrdersService.selectOrder(yunShuOrderRequest);
    }

    @PostMapping("/orderDate")
    public ResultMsg<?> orderDate(@RequestBody YunShuOrderRequest yunShuOrderRequest){
        log.info("云梳订购回传参数"+yunShuOrderRequest);
        return neimengCmccOrdersService.orderDate(yunShuOrderRequest);
    }


    public static void main(String[] args) {
        String jsonString = "{\"RSP_PARAM\":{\"BUSI_INFO\":{\"CHECK_FLAG\":\"2044\",\"CHECK_RESULT\":\"保存数据成功!\"},\"PUB_INFO\":{\"MESSAGE\":\"success\",\"CODE\":\"0\",\"REQ_SERIAL_NO\":\"NGBUSI20250220051747320687\"}}}";

        // 创建一个JSONObject实例
        JSONObject jsonObject = JSON.parseObject(jsonString);

        // 递归访问JSON对象以获取CODE值
        String code = jsonObject.getJSONObject("RSP_PARAM")
                .getJSONObject("PUB_INFO")
                .getString("CODE");

        // 打印CODE值
        System.out.println("CODE: " + code);

    }






}
